package com.dman.multi.algo;

public class SectionAlgoFactory {
	
	private String pkgName;
	private static SectionAlgoFactory secAlgoFactory;
	
	private SectionAlgoFactory(){
		pkgName = SectionAlgoFactory.class.getName();
		int index = pkgName.lastIndexOf('.') + 1;
		pkgName = pkgName.substring(0, index);
	}
	
	public static SectionAlgoFactory getInstance(){
		if(secAlgoFactory == null){
			synchronized(SectionAlgoFactory.class){
				if(secAlgoFactory == null)
					secAlgoFactory = new SectionAlgoFactory();
			}
		}
		
		return secAlgoFactory;
	}
	
	public SectionAlgo getSectionAlgo(String algo){
		algo = pkgName + algo + "SectionAlgo";
		SectionAlgo secAlg = null;
		try {
			secAlg = (SectionAlgo) Class.forName(algo).newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return secAlg;
	}
}
